//
//  STTestProtocrolController.swift
//  iPhone
//
//  Created by Toj on 4/10/23.
//

protocol VehicleProtocol {
    func starting()
}

class Vehicle: NSObject { }

class Benz: Vehicle, VehicleProtocol {
    func starting() {
        print("Starting the Benz")
    }
}

class Bike: Vehicle, VehicleProtocol {
    func starting() {
        print("Starting the Bike")
    }
}

// MARK: - 懒加载(属性), 变量, 初始化init
class STTestProtocrolController: STBaseViewController {
    
    private var mapTable: [String: VehicleProtocol] = [:]
    private func getVehicle(name: String) -> VehicleProtocol? {
        if let car = mapTable[name] { return car }
     
        if name == "Benz" {
            mapTable[name] = Benz()
        }
        else if name == "Bike"  {
            mapTable[name] = Bike()
        }
        
        return mapTable[name]
    }
}

// MARK: - 生命周期
extension STTestProtocrolController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMakeInitialize()
        setupMakeAddSubviews()
        setupMakeLayoutSubviews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
}

// MARK: - 初始化设置
private extension STTestProtocrolController {
    
    func setupMakeAddSubviews() {
        
    }
    
    func setupMakeLayoutSubviews() {
        
    }
    
    func setupMakeInitialize() {
        testAds()
    }
    
    func testAds() {
//        guard let admobModel = STAdManager.manager.appOpenAdmobModelCache() else { return }
//        STAdsManager.manager.getAdsObject(admobModel: admobModel)
//        STAdsManager.manager.getAdsObject(admobModel: admobModel)
    }
    
    func testCar() {
//        var car: VehicleProtocol?
//        var vehicle: Vehicle?
        
//        car = getVehicle(name: "Bike")
//        vehicle = car as? Vehicle
//        print("-->toj: car Bike: \(vehicle?.cm_objectAddress)")
//
//        car = getVehicle(name: "Benz")
//        vehicle = car as? Vehicle
//        print("-->toj: car Benz: \(vehicle?.cm_objectAddress)")
//
//        car = getVehicle(name: "Benz2")
//        vehicle = car as? Vehicle
//        print("-->toj: car Benz2: \(vehicle?.cm_objectAddress)")
//        car = getVehicle(name: "Bike2")
//        vehicle = car as? Vehicle
//        print("-->toj: car Bike2: \(vehicle?.cm_objectAddress)")
//
//        car = getVehicle(name: "Bike")
//        vehicle = car as? Vehicle
//        print("-->toj: car Bike: \(vehicle?.cm_objectAddress)")
//        car = getVehicle(name: "Bike")
//        vehicle = car as? Vehicle
//        print("-->toj: car Bike: \(vehicle?.cm_objectAddress)")
//
//        car = getVehicle(name: "Benz")
//        vehicle = car as? Vehicle
//        print("-->toj: car Benz: \(vehicle?.cm_objectAddress)")
//        car = getVehicle(name: "Benz")
//        vehicle = car as? Vehicle
//        print("-->toj: car Benz: \(vehicle?.cm_objectAddress)")
    }
}
/*
class STAdsObject: NSObject {
    internal  weak var _delegate: STAdmobObject2Delegate?
//    override var delegate: STAdmobObject2Delegate? {
//        get {
//            return _delegate
//        }
//        set {
//            _delegate = newValue
//        }
//    }
    
}

class STNativeAdsObject: STAdsObject {
    /* 广告对象 */
    typealias AdObject = NSObject
   
    deinit {
        print("-->toj: STNativeAdsObject2 \(cm_className) func: deinit")
    }
}
extension STNativeAdsObject: STAdmobProtocol {
    var delegate: STAdmobObject2Delegate? {
        get {
            return _delegate
        }
        set {
            _delegate = newValue
        }
    }
    
    func launchPreloadCacheAd() {
       
    }
    
    func preloadCacheAd(admobModel: STAdmobModel) {
       
    }
    
    func replacePreloadCacheAd(admobModel: STAdmobModel) {
    
    }
    
    func preloadAd(admobModel: STAdmobModel, completion: ((Bool) -> Void)?) {
    
    }
    
    func loadAd(admobModel: STAdmobModel, completion: ((Bool) -> Void)?) {
      
    }
    
    func presentAd(from vc: UIViewController) {
     
    }
}


class STNativeAdsObject2: STAdsObject {
    /* 广告对象 */
    typealias AdObject = NSObject
  
    deinit {
        print("-->toj: STNativeAdsObject2 \(cm_className) func: deinit")
    }
}

extension STNativeAdsObject2: STAdmobProtocol {
    var delegate: STAdmobObject2Delegate? {
        get {
            return _delegate
        }
        set {
            _delegate = newValue
        }
    }
    
    func launchPreloadCacheAd() {
       
    }
    
    func preloadCacheAd(admobModel: STAdmobModel) {
       
    }
    
    func replacePreloadCacheAd(admobModel: STAdmobModel) {
    
    }
    
    func preloadAd(admobModel: STAdmobModel, completion: ((Bool) -> Void)?) {
    
    }
    
    func loadAd(admobModel: STAdmobModel, completion: ((Bool) -> Void)?) {
      
    }
    
    func presentAd(from vc: UIViewController) {
     
    }
}

class STAdsManager: NSObject {
    static let manager = STAdsManager()
    
    private lazy var _mapTables: [String: STAdmobProtocol] = [:]
    func getAdsObject(admobModel: STAdmobModel) -> STAdmobProtocol? {
        let adName = STAdModelType.native.adName
        if let adsObject = _mapTables[adName] {
            return adsObject
        }
        
        switch admobModel.model {
        case .admob:
            _mapTables[adName] = STNativeAdsObject()
            break
        case .admobAppOpen:
            _mapTables[adName] = STNativeAdsObject2()
            break
        case .native:
            let s = STNativeAdsObject2()
            _mapTables[adName] = STNativeAdsObject2()
            break
        case .admobInterstitial:
            _mapTables[adName] = STNativeAdsObject2()
            break
        default:
            break
        }
        var admobObject = _mapTables[adName]
        admobObject?.delegate = self
        return admobObject
    }
    
    /* app启动 预加载 缓存的广告 */
    func launchPreloadCacheAd() {
        
    }
    
    /* 预加载 广告对象 */
    func preloadCacheAd(admobModel: STAdmobModel) {
        let admobObject = getAdsObject(admobModel: admobModel)
        admobObject?.preloadCacheAd(admobModel: admobModel)
    }
    
    /* 更新预加载 广告数据 并且预加载 广告对象 */
    func replacePreloadCacheAd(admobModel: STAdmobModel) {
        let admobObject = getAdsObject(admobModel: admobModel)
        admobObject?.replacePreloadCacheAd(admobModel: admobModel)
    }
}


extension STAdsManager: STAdmobObject2Delegate {
    
}
*/
